'use strict';

angular.module('snPaas_om')
	.controller('WorkOrderDetailCtrl',['$scope','baseUrl','workorderStore','ngDialog',function($scope,baseUrl,workorderStore,ngDialog){

		$scope.baseUrl = baseUrl.static;
		var workOrder = $scope.workNow = $scope.ngDialogData;
		var loadList = function(){
			workorderStore.getDetail(workOrder.id).then(function(data){
				$scope.converList = data;
			});	
		};
		loadList();

		$scope.sendMsg = function(){
			if($scope.newResponse.length==0){
				return;
			}
			else{
				if($scope.converList.length ==0){
					var serialNum = 1;
				}
				else{
					var serialNum = $scope.converList[$scope.converList.length-1].serialNum;
				}
				workorderStore.response({
					context: $scope.newResponse,
					workOrderId: workOrder.id,
					serialNum: serialNum
				}).then(function(){
					loadList();
					$scope.newResponse = '';
				});
			}
		};
	}]);